package cn.bdqn.web.controller.backend;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;

import cn.bdqn.entity.BackendUser;
import cn.bdqn.entity.DevUser;
import cn.bdqn.service.BackendUserService;
import cn.bdqn.service.DevUserService;

@Controller
@RequestMapping("/backendUser")
public class BackendUserController {
	
	@Autowired
	private BackendUserService backendUserService;
	
	@RequestMapping("/disLogin")
	public String disLogin(){
		return "backendLogin";
	}
	
	
	@RequestMapping("/login")
	public String login(HttpServletRequest request,HttpSession session,
						@RequestParam(value="devCode",required=false)String username,
						@RequestParam(value="devPassword",required=false)String password){
		BackendUser loginBackendUser = backendUserService.checkDevUserByUserName(username,password);
		
		if(loginBackendUser != null){
			//登陆成功
			session.setAttribute("backendUser", loginBackendUser);
			return "redirect:/backendApp/disMain";
		}else{
			//登陆失败
			request.setAttribute("loginInfo", "用户名或密码错误...");
			return "backendLogin";
		}
		
	}

}
